from selenium.webdriver.common.by import By
from base.base_action import BaseAction


# 问卷管理页面
class QuestionnaireManagementPage(BaseAction):

    # 问卷管理按钮
    questionnaire_management_btn = By.XPATH, "//span[text()='问卷管理']"

    # 关键字搜索框
    keyword_search = By.XPATH, "//input[@placeholder='搜索问卷']"

    # 组织形式筛选框
    organizational_form_filter = By.XPATH, "//input[@placeholder='组织形式']"

    # 选择学习项目
    select_learn_project = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[1]/span"

    # 选择直接发起
    select_directly_by = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[2]/span"

    # 状态筛选框
    status_filter = By.XPATH, "//input[@placeholder='状态']"

    # 选择待发布
    select_unpublished = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[1]/span"

    # 选择进行中
    select_under_way = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[3]/span"

    # 新建问卷按钮
    add_questionnaire_btn = By.XPATH, " //span[contains(text(), '新增问卷')]"

    # 复制模板按钮
    copy_template_btn = By.XPATH, "/html/body/ul/li[1]"

    # 问卷模板选择框
    questionnaire_template_select = By.XPATH, "//input[@placeholder='请选择问卷模版']"

    # 搜索模板
    search_temp = By.XPATH, "//input[@placeholder='搜索模板']"

    # 选择模板
    select_template = "document.getElementsByClassName('el-radio__inner')[1].click();"

    # 点击确定
    determine_btn = By.XPATH, "//span[text()='确 定']"

    # 问卷名称输入框
    questionnaire_name_input = By.XPATH, "//input[@placeholder='请输入问卷名称']"

    # 富文本输入框
    rich_text_input = By.CLASS_NAME, "w-e-text"

    # 开始时间选择框
    start_time_select = By.XPATH, "//input[@placeholder='选择开始时间']"
    # 选择开始时间
    select_start_time = By.XPATH, "/html/body/div[2]/div[2]/button[1]/span"

    # 结束时间选择框
    end_time_select = By.XPATH, "//input[@placeholder='选择结束时间']"

    # 选择结束时间
    select_end_time1 = By.XPATH, "/html/body/div[3]/div[1]/div/div[2]/button[4]"
    select_end_time2 = By.XPATH, "/html/body/div[3]/div[1]/div/div[3]/table[1]/tbody/tr[4]/td[1]/div/span"

    # 回收上限输入框
    upper_bound_input = By.XPATH, "//input[@autocomplete='off' and @max='100000']"

    # 下一步按钮
    next_btn = By.XPATH, "//div[1]//div[3]/div[3]//div[2]/main//div[2]//button[1]/span"

    # 问卷内容页面下一步按钮
    next_btn1 = "document.getElementsByClassName('el-button el-button--primary')[5].click();"

    # 指定人员填写复选框
    checkbox = "document.getElementsByClassName('el-checkbox__inner')[3].click();"

    # 添加用户按钮
    add_user_btn = By.XPATH, "//span[text()='移除用户']/parent::button/preceding-sibling::button"

    # 全选框
    select_all = "document.getElementsByClassName('el-checkbox__inner')[6].click();"

    # 确定按钮
    determine_btn1 = By.XPATH, "/html/body/div[2]/div/div[3]/div/button[1]"

    # 发布按钮
    publish_btn = By.XPATH, "//span[text()='发布']"

    # 直接新建
    new_direct = By.XPATH, "/html/body/ul/li[2]"

    # 点击问卷管理
    def click_questionnaire_management_btn(self):
        return self.click(self.questionnaire_management_btn)

    # 输入问卷名称进行搜索
    def input_questionnaire_name(self, content):
        return self.input(self.keyword_search, content)

    # 点击组织形式筛选框
    def click_organizational_form_filter(self):
        return self.click(self.organizational_form_filter)

    # 选择学习项目
    def click_select_learn_project(self):
        return self.click(self.select_learn_project)

    # 选择直接发起
    def click_select_directly_by(self):
        return self.click(self.select_directly_by)

    # 点击状态筛选框
    def click_status_filter(self):
        return self.click(self.status_filter)

    # 选择待发布
    def click_select_unpublished(self):
        return self.click(self.select_unpublished)

    # 选择进行中
    def click_select_under_way(self):
        return self.click(self.select_under_way)

    # 点击新建问卷
    def click_add_questionnaire_btn(self):
        return self.click(self.add_questionnaire_btn)

    # 点击复制模板
    def click_copy_template_btn(self):
        return self.click(self.copy_template_btn)

    # 点击问卷模板输入框
    def click_questionnaire_template_select(self):
        return self.click(self.questionnaire_template_select)

    # 搜索模板
    def input_search_temp(self, content):
        self.input(self.search_temp, content)
        return self.click_keys_enter(self.search_temp)

    # 选择模板
    def click_select_template(self):
        return self.execute_js(self.select_template)

    # 点击确定
    def click_determine_btn(self):
        return self.click(self.determine_btn)

    # 输入问卷名称
    def input_questionnaire_name_input(self, content):
        return self.input(self.questionnaire_name_input, content)

    # 输入问卷说明
    def input_questionnaire_declare(self, content):
        return self.input(self.rich_text_input, content)

    # 选择开始时间输入框
    def click_start_time_select(self):
        self.click(self.start_time_select)
        return self.click(self.select_start_time)

    # 选择结束时间
    def click_end_time_select(self):
        self.click(self.end_time_select)
        self.click(self.select_end_time1)
        return self.click(self.select_end_time2)

    # 输入回收上限
    def input_upper_bound(self, content):
        return self.input(self.upper_bound_input, content)

    # 点击下一步按钮
    def click_next_btn(self):
        return self.click(self.next_btn)

    # 问卷内容页面的下一步按钮
    def click_next_btn1(self):
        return self.execute_js(self.next_btn1)

    # 勾选指定人员填写
    def click_checkbox(self):
        return self.execute_js(self.checkbox)

    # 点击添加用户按钮
    def click_add_user_btn(self):
        return self.click(self.add_user_btn)

    # 全选框
    def click_select_all(self):
        return self.execute_js(self.select_all)

    # 点击确定按钮
    def click_determine_btn1(self):
        return self.click(self.determine_btn1)

    # 点击发布按钮
    def click_publish_btn(self):
        return self.click(self.publish_btn)

